package com.fxhy.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baby.myutils.DateUtils;
import com.fxhy.mapper.IndexMapper;
import com.fxhy.vo.EveryDayDataVo;
import com.fxhy.vo.IndexVo;

@Service
public class IndexService {
	@Autowired
	private IndexMapper indexMapper;
	
	public IndexVo findIndexData(Integer userId) {
		//今日日期字符串
		IndexVo index = indexMapper.findIndexData(userId,DateUtils.getNowDate().substring(0,8));
	
		List<EveryDayDataVo> list = indexMapper.findEveryDayUserNum(userId,DateUtils.getNowDate().substring(0,6));
		List<Integer> newlist = new ArrayList<Integer>();
		for(int i = 1;i <= 31;i++){
			boolean flag = false;
			two:for(EveryDayDataVo vo : list){
				if(Integer.parseInt(vo.getDay()) == i){
					newlist.add(vo.getUserNum());
					flag = true;
					break two;
				}
			}
			if(!flag){
				newlist.add(0);
			}
		}
		index.setToMonth(DateUtils.getNowDate().substring(4,6));
		index.setEveryDayUserNum(newlist);
		return index;
	}
}
